<template>
  <a-modal 
    :title="title" 
    :width="800" 
    :visible="visible" 
    :confirmLoading="confirmLoading" 
    cancelText="关闭"
    @ok="closeModal" 
    @cancel="closeModal" 
  >
    <a-spin :spinning="confirmLoading">
      <!-- table区域-begin -->
      <div>
        <a-table 
          ref="table" 
          size="middle" 
          rowKey="id" 
          :columns="tableColumns" 
          :dataSource="tableData" 
          :loading="loading" 
          @change="handleTableChange">
          <!--操作-->
          <span slot="action" slot-scope="text, record">
            <a-button @click="choose(record)" type="primary">选择</a-button>
          </span>
        </a-table>
      </div>
    </a-spin>
  </a-modal>
</template>

<script>
import ApiTree from "@/api/merchant/merchantList";
import { Slime } from '@/mixins/slime';
export default {
  name: 'serviceListModal',
  mixins: [Slime],
  data() {
    return {
      title: '详情',
      merchantId:0,
      tableColumns: [
        { title: "客服姓名", dataIndex: "nickname", align: "center" },
        {
          title: "操作",
          scopedSlots: { customRender: "action" },
          align: "center"
        }
      ],
      tableData: [],
      BuildingList:[],
    };
  },
  methods: {
    //初始加载
    open(merchantId) {
      this.merchantId = merchantId
      this.visible = true;
      this.loadData();
    },
    //加载的会员
    loadData(arg) {
      const that = this;
      // if (arg === 1) {
      //   this.ipagination.current = 1;
      // }
      this.loading = true;
      let params = this.getQueryParams(); // 查询条件
      ApiTree.serviceList(params)
        .then((res) => {
          let data = res.result;
          this.tableData = data;
          // 页码
          // this.ipagination.total = res.result.total;
        })
        .finally(() => {
          this.loading = false;
        });
    },
    //选中客服
    choose(record) {
      const that = this;
      let param = {
        merchantIds: this.merchantId,
        userId: record.id,
      }
      ApiTree.serviceUpdate(param)
        .then((res) => {
          if(res.code == 0){
            that.$message.success('操作成功');
          }else{
            that.$message.warning(res.message);
          }
        })
        .finally(() => {
          that.closeModal();
        });
    },
    // 弹窗-关闭
    closeModal() {
      this.visible = false;
      this.$emit('closeModal');
    },
  },
};
</script>

<style scoped>
</style>